<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QAbstractFileEngineHandler Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QAbstractFileEngineHandler Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QAbstractFileEngineHandler class provides a way to register
custom file engines with your application. <a href="#details">More...</a></p>

<h3>Methods</h3><ul><li><div class="fn" /><b><a href="qabstractfileenginehandler.html#QAbstractFileEngineHandler">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qabstractfileenginehandler.html#QAbstractFileEngineHandler-2">__init__</a></b> (<i>self</i>, QAbstractFileEngineHandler)</li><li><div class="fn" />QAbstractFileEngine <b><a href="qabstractfileenginehandler.html#create">create</a></b> (<i>self</i>, QString&#160;<i>fileName</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QAbstractFileEngineHandler class provides a way to register
custom file engines with your application.</p>
<p>QAbstractFileEngineHandler is a factory for creating <a href="qabstractfileengine.html">QAbstractFileEngine</a> objects (file
engines), which are used internally by <a href="qfile.html">QFile</a>, <a href="qfileinfo.html">QFileInfo</a>, and
<a href="qdir.html">QDir</a> when working with files and
directories.</p>
<p>When you open a file, Qt chooses a suitable file engine by
passing the file name from <a href="qfile.html">QFile</a> or
<a href="qdir.html">QDir</a> through an internal list of registered
file engine handlers. The first handler to recognize the file name
is used to create the engine. Qt provides internal file engines for
working with regular files and resources, but you can also register
your own <a href="qabstractfileengine.html">QAbstractFileEngine</a>
subclasses.</p>
<p>To install an application-specific file engine, you subclass
QAbstractFileEngineHandler and reimplement <a href="qabstractfileenginehandler.html#create">create</a>(). When you
instantiate the handler (e.g. by creating an instance on the stack
or on the heap), it will automatically register with Qt. (The
latest registered handler takes precedence over existing
handlers.)</p>
<p>For example:</p>
<pre class="cpp">
 <span class="keyword">class</span> ZipEngineHandler : <span class="keyword">public</span> <span class="type">QAbstractFileEngineHandler</span>
 {
 <span class="keyword">public</span>:
     <span class="type"><a href="qabstractfileengine.html">QAbstractFileEngine</a></span> <span class="operator">*</span>create(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>fileName) <span class="keyword">const</span>;
 };

 <span class="type"><a href="qabstractfileengine.html">QAbstractFileEngine</a></span> <span class="operator">*</span>ZipEngineHandler<span class="operator">.</span><a href="qabstractfileenginehandler.html#create">create</a>(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>fileName) <span class="keyword">const</span>
 {
     <span class="comment">// ZipEngineHandler returns a ZipEngine for all .zip files</span>
     <span class="keyword">return</span> fileName<span class="operator">.</span>toLower()<span class="operator">.</span>endsWith(<span class="string">".zip"</span>) <span class="operator">?</span> <span class="keyword">new</span> ZipEngine(fileName) : <span class="number">0</span>;
 }

 <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span><span class="operator">*</span>argv)
 {
     <span class="type"><a href="qapplication.html">QApplication</a></span> app(argc<span class="operator">,</span> argv);

     ZipEngineHandler engine;

     MainWindow window;
     window<span class="operator">.</span>show();

     <span class="keyword">return</span> app<span class="operator">.</span>exec();
 }
</pre>
<p>When the handler is destroyed, it is automatically removed from
Qt.</p>
<p>The most common approach to registering a handler is to create
an instance as part of the start-up phase of your application. It
is also possible to limit the scope of the file engine handler to a
particular area of interest (e.g. a special file dialog that needs
a custom file engine). By creating the handler inside a local
scope, you can precisely control the area in which your engine will
be applied without disturbing file operations in other parts of
your application.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QAbstractFileEngineHandler" />QAbstractFileEngineHandler.__init__ (<i>self</i>)</h3><p>Constructs a file handler and registers it with Qt. Once created
this handler's <a href="qabstractfileenginehandler.html#create">create</a>() function will
be called (along with all the other handlers) for any paths used.
The most recently created handler that recognizes the given path
(i.e. that returns a <a href="qabstractfileengine.html">QAbstractFileEngine</a>) is used for the
new path.</p>
<p><b>See also</b> <a href="qabstractfileenginehandler.html#create">create</a>().</p>


<h3 class="fn"><a name="QAbstractFileEngineHandler-2" />QAbstractFileEngineHandler.__init__ (<i>self</i>, <a href="qabstractfileenginehandler.html">QAbstractFileEngineHandler</a>)</h3><h3 class="fn"><a name="create" /><a href="qabstractfileengine.html">QAbstractFileEngine</a> QAbstractFileEngineHandler.create (<i>self</i>, QString&#160;<i>fileName</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>Creates a file engine for file <i>fileName</i>. Returns 0 if
this file handler cannot handle <i>fileName</i>.</p>
<p>Example:</p>
<pre class="cpp">
 <span class="type">QAbstractSocketEngine</span> <span class="operator">*</span>ZipEngineHandler<span class="operator">.</span>create(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>fileName) <span class="keyword">const</span>
 {
     <span class="comment">// ZipEngineHandler returns a ZipEngine for all .zip files</span>
     <span class="keyword">return</span> fileName<span class="operator">.</span>toLower()<span class="operator">.</span>endsWith(<span class="string">".zip"</span>) <span class="operator">?</span> <span class="keyword">new</span> ZipEngine(fileName) : <span class="number">0</span>;
 }
</pre>
<p><b>See also</b> <a href="qabstractfileengine.html#create">QAbstractFileEngine.create</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;4.9.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2011</td><td align="right" width="25%">Qt&#160;4.8.0</td></tr></table></div></address></body></html>